Optional texturebanks.f

Requires SDL
Requires Tools
Requires Seki
Requires SORA\Images
Requires Vectors
Requires GL-Tools
Requires Dorothy.f

Only Forth Definitions

image extend: texbank
   64 int.field[] sections
end-type

\ Adds X and Y to the X and Y of each subimage in an image, also storing what the offset is
\   in ->TEXTURE-X and ->TEXTURE-Y.
0 subimage.ref siptr
method: image.offset-subimages   ( x y image -- )
   subimages if
      2dup texture-x.2!   \ store current offset
      subimages to siptr begin
         siptr h@ $FFFF <> while
         over siptr.x.+!
         dup siptr.y.+!
         12 +to siptr
      repeat
   then
   2drop ;

rectangle.make dest-rect

\ Loads the images described in a texbank, constructing one large surface out of them.
\   Also transforms subimage coordinates by their location in the texbank.
method: texbank.init ( texbank -- )
   sections
   8 0 do
      8 0 do
         i 256 *   j 256 *   dest-rect.x.2!
         @+ ?dup if
            \ dup i j offset-subimages
            image.surface 0 surface dest-rect sdl-blit
         then
     loop
  loop
  surface.colorkey-alpha drop
  drop ;

\ Table of 64 cells must follow
: Texbank: ( -- <name> )
    2048 2048 Image.new image.const ;
